<template >
  <div id="AddDiscussTopicDialog">
    <el-button type="text" @click="dialogFormVisible = true"
    >添加话题</el-button
    >
    <el-dialog v-model="dialogFormVisible" title="Shipping address">
      <el-form >
        <el-form-item label="讨论标题" :label-width="formLabelWidth">
          <el-input v-model="form.topic" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item  label="讨论内容" :label-width="formLabelWidth">
          <qul-edit :ref="'qul'"></qul-edit>
        </el-form-item>

      </el-form>
      <template style="padding-top: 200px" #footer>
      <span class="dialog-footer" style="margin-top: 12px">
        <el-button @click="dialogFormVisible = false">Cancel</el-button>
        <el-button type="primary" @click="upload()"
        >Confirm</el-button>
      </span>
      </template>
    </el-dialog>
  </div>

</template>

<script>
import axios from "axios";
import { defineComponent, reactive, toRefs } from 'vue'
import QulEdit from "./qulEdit";
export default {
  name: "AddContentDiscussion",
  components: {QulEdit},
  setup() {
    const state = reactive({
      dialogFormVisible: false,
      form: {
        topic: '',
        content: '',
      },
      formLabelWidth: '120px',

    })

    return {
      ...toRefs(state),
    }
  },
  methods:{

    upload(){
      this.form.content=this.$refs.qul.covert2Html()
      this.dialogFormVisible = false
      axios.post("/api/teacher/AddNewDiscussTopic",this.form).then((res)=>{
        if (res.status===200){
          alert("ok")
          this.$parent.setUpData()
        }
      })
    }
  }
}
</script>

<style>

#AddDiscussTopicDialog .el-dialog .el-dialog__footer{
  margin-top: 60px !important;
}
</style>